package cn.yuanqiao.web.controller.archive.storeRoom;

import cn.yuanqiao.archive.storeRoom.domain.OutInLogs;
import cn.yuanqiao.archive.storeRoom.service.IOutInLogsService;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 出入库日志Controller
 * 
 * @author xy
 * @date 2023-06-30
 */
@RestController
@RequestMapping("/archive/OutInLogs")
public class OutInLogsController extends BaseController
{
    @Autowired
    private IOutInLogsService outInLogsService;

    /**
     * 查询出入库日志列表
     */
/*
    @PreAuthorize("@ss.hasPermi('storeroom:OutInLogs:list')")
*/
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:entryExitRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(OutInLogs outInLogs) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        startPage();
        if(outInLogs.getEdCrkqr()!=null){
            outInLogs.setEdCrkqr(sdf1.parse(sdf.format(outInLogs.getEdCrkqr())+" 23:59:59"));

        }
        List<OutInLogs> list = outInLogsService.selectOutInLogsList(outInLogs);
        return getDataTable(list);
    }

    /**
     * 导出出入库日志列表
     */
    @PreAuthorize("@ss.hasPermi('storeroom:OutInLogs:export')")
    @Log(title = "出入库日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OutInLogs outInLogs)
    {
        List<OutInLogs> list = outInLogsService.selectOutInLogsList(outInLogs);
        ExcelUtil<OutInLogs> util = new ExcelUtil<OutInLogs>(OutInLogs.class);
        util.exportExcel(response, list, "出入库日志数据");
    }

    /**
     * 获取出入库日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('storeroom:OutInLogs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(outInLogsService.selectOutInLogsById(id));
    }

    /**
     * 新增出入库日志
     */
    @PreAuthorize("@ss.hasPermi('storeroom:OutInLogs:add')")
    @Log(title = "出入库日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OutInLogs outInLogs)
    {
        return toAjax(outInLogsService.insertOutInLogs(outInLogs));
    }

    /**
     * 修改出入库日志
     */
    @PreAuthorize("@ss.hasPermi('storeroom:OutInLogs:edit')")
    @Log(title = "出入库日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OutInLogs outInLogs)
    {
        return toAjax(outInLogsService.updateOutInLogs(outInLogs));
    }

    /**
     * 删除出入库日志
     */
    @PreAuthorize("@ss.hasPermi('storeroom:OutInLogs:remove')")
    @Log(title = "出入库日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(outInLogsService.deleteOutInLogsByIds(ids));
    }
}
